#目录信息
CURDIR := $(shell pwd)
SOURCEDIR = $(CURDIR)/source/
OBJDIR := $(CURDIR)/objs/
BINDIR := $(CURDIR)/bin/
INCLUDEDIR := $(CURDIR)/include/
LIBDIR := $(CURDIR)/lib/

#编译器
CC = gcc
## 编译选项
CFLAGS = -Wall -O -g -I$(INCLUDEDIR) -L$(LIBDIR)
## 目标文件
TARGET = $(BINDIR)main
SRCS := $(wildcard $(SOURCEDIR)*.c)
#SRC := $(wildcard $(SRCDIR)/*.c)
OBJS := $(patsubst $(SOURCEDIR)%.c, $(OBJDIR)%.o,$(SRCS))
#OBJS = $(OBJ_DIR)*.o
#OBJS = $(SRCS:.c=:.o)
#OBJS := $(SRCS:.c=.o)
#OBJS := $(OBJS:$(OBJDIR)=)
a:
	echo "CURDIR = $(CURDIR)"
	echo "SOURCEDIR = $(SOURCEDIR)"
	echo "OBJDIR = $(OBJDIR)"
	echo "BINDIR = $(BINDIR)"
	echo "INCLUDEDIR = $(INCLUDEDIR)"
	echo "LIBDIR = $(LIBDIR)"
	echo "TARGET = $(TARGET)"
	echo "SRCS = $(SRCS)"
	echo "OBJS = $(OBJS)"
# 默认目标
all: $(TARGET)
# 目标文件生成规则
$(TARGET): $(OBJS)
	$(CC) $(CFLAGS) -o $@ $^
# 中间文件生成规则
#解释：makefile 隐含规则，这句话的意思就是 %.o : %.c，也就是说，所有的.o文件，依赖于对应的.c文件
$(OBJS): $(OBJDIR)%.o : $(SOURCEDIR)%.c
	$(CC) $(CFLAGS) -c -o $@ $^
# 清理规则
.PHONY:clean
clean:
	rm -f $(TARGET) $(OBJS)

